home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / SplitNMail.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-24  |  3KB  |  95 lines

  1. /*                            Split'n'Mail
  2.                              v1.2 24-Jun-97
  3.  
  4.   Script for splitting and posting a long ASCII file.
  5.  
  6.   Requirements:
  7.     - YAM 
  8.     - reqtools.library
  9.     - rexxsupport.library
  10.     - rexxreqtools.library
  11.     - a really long ascii file you want to mail
  12.  
  13.   Operation:
  14.     - The script splits the file automatically OR when a line consisting only
  15.       '.break' (without quotes) is encountered.
  16.     - By changing the value of use_separators, you can decide if the parts are
  17.       enclosed between the following lines:
  18.       BEGIN PART 6 --- *** --- *** --- *** ---
  19.       END PART 6 --- *** --- *** --- *** ---
  20.   
  21.   Send bug reports, comments and hate mail to knikulai@utu.fi.  
  22.  
  23.   If you want to get the list of my AREXX-scripts or their latest versions, 
  24.   send mail to knikulai@utu.fi with subject 'request' and words 'help' and
  25.   'allfiles' in the message body, both on it's own line.
  26. */
  27.  
  28. options results
  29. breakline='.break'    /* You can change this to anything you like */
  30. use_separators='yes'    /* This value should be 'yes' or 'no' */
  31. tmp='t:'        /* Temporary files are stored here.  You might want to
  32.                            change this if you are low on memory or the file is 
  33.                very large. */
  34.  
  35. title="Split'n'Mail by knikulai@utu.fi"
  36. butts='_Ok|_Cancel'    /* :-) I know it's childish... :-) */
  37. tags='rt_pubscrname=YAMSCREEN'  /* Change here the name of the screen YAM runs */
  38. call addlib('rexxreqtools.library',0,-30)
  39. call addlib('rexxsupport.library',0,-30)
  40.  
  41. email=rtgetstring('','Enter recipients e-mail address',title,butts,tags,selection)
  42. if selection=0 then call ErrorMsg("You must enter an address!")
  43.  
  44. filename=rtfilerequest('','','Select file to post',,tags)
  45. if filename='' | ~exists(filename) then call ErrorMsg("File doesn't exist!")
  46.  
  47. maxl=rtgetlong(400,'How many lines per part?',title,butts,tags,selection)
  48. if selection=0 | maxl<50 then call ErrorMsg("Too few lines per part!")
  49.  
  50. subj=rtgetstring(filename,'Enter subject of post',title,butts,tags,selection)
  51. if selection=0 then call ErrorMsg("You must enter a subject!")
  52.  
  53. ok=open(infile,filename,'R')
  54. if ~ok then call ErrorMsg("Can't open file!")
  55.  
  56. fc=1  /* part counter */
  57.  
  58. do while ~eof(infile)
  59.   ok=open(outfile,tmp || fc,'W')
  60.   if ~ok then call ErrorMsg("Could not open file for part "llfc)
  61.   if upper(use_separators)='YES' then call writeln(outfile,'BEGIN PART '||fc||' --- *** --- *** --- *** ---')
  62.   lc=0 /* line counter */
  63.   do until line=breakline | lc=maxl | eof(infile)
  64.     line=readln(infile)
  65.     lc=lc+1
  66.     if line~=breakline then do
  67.         n=writeln(outfile,line)
  68.     if n<=length(line) then call ErrorMsg("Can't write to file!")
  69.     end
  70.   end /* until line=breakline l lc=maxl */
  71.   if upper(use_separators)='YES' then call writeln(outfile,'END PART '||fc||' --- *** --- *** --- *** ---')
  72.   call close(outfile)
  73.   if ~eof(infile) then fc=fc+1
  74. end /* until eof(infile) */
  75.  
  76. address 'YAM'
  77. do i=1 to fc
  78.   'MailWrite'
  79.   'WriteMailTo "' || email ||'"'
  80.   'WriteSubject "'|| subj || ' (' || i || '/' || fc || ')"'
  81.   'WriteLetter "' || tmp || i || '"'
  82.   'WriteQueue'
  83.   call delete(tmp || i)
  84. end /* i=1 to fc */
  85.  
  86. call TheEnd /* Goodbye! */
  87.  
  88. ErrorMsg:
  89.     parse arg s
  90.     call rtezrequest(s,"_Exit","Split'n'Mail error",tags)
  91. TheEnd:
  92.     call remlib('rexxreqtools.library')
  93.     call remlib('rexxsupport.library')
  94.     exit /* All good things must eventually come to an end :-) */
  95.